<?php
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
	/* special ajax here */
	require_once ("connect.php"); 

	if(isset($_GET['action'])){
		$action = $_GET['action'];
		switch ($action) {
			case 'read':
				$sql = "select * from account";
				$statement = $db->query($sql);
				$statement->execute();
				$statement->setFetchMode(PDO::FETCH_ASSOC);
				$array = array();
				while($row = $statement->fetch()){
					array_push($array, $row);
				}
				echo json_encode(array("accounts"=>$array));
				break;
			case 'update' : 
				$id = $_GET['id'];
				$username = $_GET['username'];
				$fullname = $_GET['fullname'];
				$address = $_GET['address'];
				$phone = $_GET['phone'];
				$biling = $_GET['billing_address'];
				$note = $_GET['note'];
				$sql = "update account set username = ?,fullname = ?,address = ?, phone = ?,billing_address =?,note=? where username = ?";
				$statement = $db->prepare($sql);
				$data = array($username,$fullname,$address,$phone,$biling,$note,$id);
				$statement->execute($data);
				echo json_encode(array("statusUpdate"=>"success"));
				break;
			default:
				# code...
			break;
		}

	}

}

?>